package com.github.thinwonton.springboot.showcase.multidatasource.service;

import com.github.thinwonton.springboot.showcase.multidatasource.config.DS;
import com.github.thinwonton.springboot.showcase.multidatasource.config.DatabaseType;
import com.github.thinwonton.springboot.showcase.multidatasource.constant.OrderConstants;
import com.github.thinwonton.springboot.showcase.multidatasource.dao.OrdersDao;
import com.github.thinwonton.springboot.showcase.multidatasource.entity.Orders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * OrdersService
 *
 * @author hugo
 * @date 2018/8/22
 */
@Service
public class OrdersService {

    @Autowired
    private OrdersDao ordersDao;

    @DS(DatabaseType.ORDERS)
    @Transactional(rollbackFor = Exception.class)
    public void createOrder() {
        Orders record = new Orders();
        record.setStatus(OrderConstants.ORDER_STATUS_PAID);
        ordersDao.insert(record);
    }

    @DS(DatabaseType.ORDERS)
    public List<Orders> selectAll() {
        List<Orders> ordersList = ordersDao.selectAll();
        return ordersList;
    }

}
